
<ui:composition  xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:p="http://primefaces.org/ui" >
    
    <h:form id="buscar_form" acceptcharset="utf-8"> 

        <p:panel>
            <p:messages  id="msg" />
            <f:validateBean disabled="true">
                <h:panelGrid columns="2" id="panelGridEscolha" styleClass="textAlignRight" columnClasses="textAlignRight">

                    <h:outputLabel value="Cód. Protocolo: " />

                    <p:inputText  value="#{managerProtocoloSelo.buscarProtocolo.id}" size="29"/>

                    <h:outputLabel value="Cliente: "/>
                    <p:autoComplete id="cliente" value="#{managerProtocoloSelo.buscarProtocolo.cliente}" 
                                    completeMethod="#{managerPessoa.autoComplete}"  
                                    var="c" itemLabel="#{c.nome}" itemValue="#{c}" 
                                    converter="pessoaConverter" forceSelection="true" 
                                    converterMessage="Erro, verifique o Cliente" 
                                    minQueryLength="3" scrollHeight="200" dropdown="true" size="26"> 
                    </p:autoComplete>

                    <h:outputLabel value="Data :"/>
                    <p:calendar value="#{managerProtocoloSelo.buscarProtocolo.dataCad}" 
                                mode="popup" showOn="both" pattern="dd/MM/yyyy" size="26"/>
                    <h:outputLabel />
                </h:panelGrid> 
            </f:validateBean>
            <div class="buttonAction">
                <p:commandButton value="Buscar" icon="ui-icon-search" 
                                 actionListener="#{managerProtocoloSelo.buscar()}"
                                 update="@form, protocoloTable, msg"/>
                <p:commandButton value="Limpar" icon="ui-icon-circle-close" actionListener="#{managerProtocoloSelo.init()}" update="@form, protocoloTable, msg"/>
            </div>


            <br/>
            <p:dataTable id="protocoloTable" var="protocolo" value="#{managerProtocoloSelo.protocolos}" 
                         paginator="true" rows="5"
                         paginatorPosition="bottom"
                         paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} "  
                         rowsPerPageTemplate="5,10,15"
                         emptyMessage="Nenhum Registro Encontrado">    

                <f:facet name="header">  
                    Dados Protocolos
                </f:facet>

                <p:column  style="width:5px;" >  
                    <p:rowToggler/>
                </p:column>

                <p:column  style="width:100px;">  
                    <f:facet name="header" >   
                        Código
                    </f:facet>  
                    <h:outputText value="#{protocolo.id}"   />  
                </p:column>

                <p:column  style="width:300px;">  
                    <f:facet name="header" >   
                        Cliente
                    </f:facet>  
                    <h:outputText value="#{protocolo.cliente.nome}"   />  
                </p:column>


                <p:column  style="width:150px;">  
                    <f:facet name="header" >   
                        Data
                    </f:facet>  
                    <h:outputText value="#{protocolo.dataCad}" >
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </h:outputText>  
                </p:column>

                <p:column  style="width:100px;">  
                    <f:facet name="header" >   
                        Valor
                    </f:facet>  
                    <h:outputText value="#{managerConsultarProtocolo.valorDoProtocolo(protocolo)}"  />  
                </p:column>

                <p:column  style="width:50px; text-align: center">  
                    <f:facet name="header" >   
                        Situação
                    </f:facet>  
                    <p:graphicImage url="/media/img/selo.jpg" style="width:24px; margin-left: 10px; "
                                    rendered="#{managerConsultarProtocolo.pendenteSelo(protocolo.id)}"
                                    title="Selos Pendente" />
                    <p:graphicImage url="/media/img/ok.png"  
                                    rendered="#{!managerConsultarProtocolo.pendenteSelo(protocolo.id) and !managerConsultarProtocolo.pendenteSelo(protocolo.id) }"
                                    title="Protocolo Finalizado" />


                </p:column>
                <p:column  style="width:100px;">  
                    <f:facet name="header" >   
                        Opções
                    </f:facet>  
                    <p:commandButton icon="ui-icon-search" title="Ver" label="Ver"
                                                     actionListener="#{managerVisualizarProtocolo.ver(protocolo.id)}" 
                                                     update="@form"/>
                    
                    <p:commandButton icon="ui-icon-check" title="Selar" label="Selar"
                                     actionListener="#{managerProtocoloSelo.protocoloToSelar(protocolo.id)}" 
                                     update="@form, :tabView"
                                     disabled="#{!managerConsultarProtocolo.pendenteSelo(protocolo.id) and !managerConsultarProtocolo.pendenteSelo(protocolo.id) }"/>
                    
                    <p:commandButton icon="ui-icon-stop" title="Cancelar Selamento" label="Cancelar Selamento"
                                      actionListener="#{managerProtocoloSelo.cancelarSeloProtocolo(protocolo.id)}" 
                                       update="@form, :tabView"
                                     disabled="#{managerConsultarProtocolo.pendenteSelo(protocolo.id) and managerConsultarProtocolo.pendenteSelo(protocolo.id) }"/>
                    
                    
        
                    
                </p:column>

                <p:rowExpansion>
                    <h:outputLabel value="Serviços do Protocolo" />
                    <table style="width:100%">
                        <tbody style="background-color: #5277A9; color: #ffffff; ">
                            <td style="font-weight: bold; text-align: center;">
                                Ato Item
                            </td>
                            <td style="font-weight: bold; text-align: center;">
                                Cartório
                            </td>
                            <td style="font-weight: bold; text-align: center;">
                                Fermojupi
                            </td>
                            <td style="font-weight: bold; text-align: center;" >
                                Valor
                            </td>
                            <td style="font-weight: bold; text-align: center;" >
                                Selos
                            </td>

                        </tbody>
                        <ui:repeat value="#{protocolo.servicoProtocolos}" var="servico">
                            <tr>
                                <td style="text-align: center;">
                                    <h:outputLabel value="#{servico.atoItem.codigo}" /> - 
                                    <h:outputLabel value="#{servico.atoItem.descricao}" /></td>
                                <td style="text-align: center;"><h:outputLabel value="#{servico.valorCartorio}" /></td>
                                <td style="text-align: center;" ><h:outputLabel value="#{servico.valorFermojupi}" /></td>
                                <td style="text-align: center;"><h:outputLabel value="#{servico.valor}" /></td>
                                <td style="text-align: center;">
                                    <ui:repeat value="#{servico.selos}" var="sel">
                                        <p:commandLink id="selos" title="Número: #{sel.numero} - Serie: #{sel.serie}"  
                                                       actionListener="#{managerProtocoloSelo.protocoloGetSelos(sel.id)}"
                                                       oncomplete="protDlg.show()"  update=":tabView:buscar_form:pesquisarProtocoloDlg"  >
                                            <div style="width: 30px; height:30px; float:left; margin-left: 2px;
                                                 background-color: \##{sel.tipoSelo.corSelo.cor};">
                                            </div>
                                        </p:commandLink>
                                    </ui:repeat>


                                </td>
                            </tr>
                        </ui:repeat>

                    </table>

                </p:rowExpansion>
            </p:dataTable> 
            
             <p:dialog  header="Cancelar Selamento de Protocolo" widgetVar="confirmCancel" modal="true">  
             
            <h:outputLabel value="Você está preste a cancelar o selamento do protocolo ! " />
            <br/>
            <br/>
            <br/>
            <center>
            <h:outputLabel value="Deseja continuar ?" />
            </center>
            
            <f:facet name="footer">
                <div class="buttonAction">
                      <p:commandButton icon="ui-icon-check" value="Sim" title="Selar" label="Selar"
                                     actionListener="#{managerProtocoloSelo.cancelarSeloProtocolo(protocolo.id)}" 
                                     update="@form, :tabView" oncomplete="confirmCancel.hide()"/>
                      
                    <p:commandButton value="Não" icon="ui-icon-close" onclick="confirmCancel.hide()"/>
                </div>
            </f:facet>
        </p:dialog>
            
            <div class="buttonAction">
                <p:commandButton id="limpar" icon="ui-icon-arrowreturnthick-1-w" 
                                 value="Voltar"
                                 actionListener="#{managerConsultarProtocolo.redirect('protocolo.xhtml')}" immediate="true" />
            </div> 
        </p:panel>
        
        
        
        
        <p:dialog  header="Informações do Selo" widgetVar="protDlg" modal="true">  
            <h:panelGrid columns="2" id="pesquisarProtocoloDlg" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                <h:outputLabel value="Número: " />

                <p:row>
                    <h:outputText value="#{managerProtocoloSelo.seloVerBuscar.numero}"/>
                    <h:outputLabel value="Série: " style="font-weight: bold; float: none;"/>
                    <h:outputText value="#{managerProtocoloSelo.seloVerBuscar.serie}"/>
                </p:row>
                <h:outputLabel value="Tipo de Selo " />
                <h:outputText value="#{managerProtocoloSelo.seloVerBuscar.tipoSelo.nome}"/>
                <h:outputLabel value="Data Entrada: " />
                <h:outputText value="#{managerProtocoloSelo.seloVerBuscar.detalheEntradaSelo.entradaSelo.dataEntrada}">
                    <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"/>
                </h:outputText>
                <h:outputLabel value="Fornecedor: " />
                <h:outputText value="#{managerProtocoloSelo.seloVerBuscar.detalheEntradaSelo.entradaSelo.fornecedor.nome}"/>
                <h:outputLabel value="Comentário: " />
                <h:outputText value="#{managerProtocoloSelo.seloVerBuscar.detalheEntradaSelo.entradaSelo.comentario}"/>
            </h:panelGrid>
            <f:facet name="footer">
                <center>
                    <p:commandButton value="Fechar" icon="ui-icon-close" onclick="protDlg.hide()"/>
                </center>
            </f:facet>
        </p:dialog>
        <br/>
    </h:form>
</ui:composition>